# encoding: utf-8


"""

@author: tongzhenguo

@time: 2021/6/20 下午4:04

@desc:

通用方法工具类
"""


def array_min(arr, default):
    """计算字符串形式的数组的最小值
    比如"1,3,4"代表三年净利润值数组，算法结果应该返回1
    如果输入数组含有非法值，可以使用default值进行替换
    """
    min_val = None
    for xx in arr:
        try:
            v = float(xx)
        except:
            v = default
        if not min_val or min_val > v:
            min_val = v
    return min_val


def valid_check(eps, col, code):
    """验证字段值是否合法，不法返回-1"""
    if eps != eps or str(eps) in ("-1", "nan") or not eps:
        print("%s %s %s nan" % (code, col, eps))
        return -1


def value_rectify(val, default):
    """矫正字段，重置为默认值
    比如股息率为空等价于股息率为0
    """
    if val != val or str(val) in ("-1", "nan"):
        return default
    else:
        return val
